<template>
  <div class="shopscard">
    <div class="shopscard-nav">
      <div
        class="nav-name"
        v-for="(item, index) in shopsnavlist"
        :key="index"
        @click="handset(index)"
        :class="index == tabIndex ? 'active' : ''"
      >
        <h3>{{ item.one }}</h3>
        <p>{{ item.two }}</p>
      </div>
    </div>
    <ShopCard
      :itm="item"
      class="ShopCard-shop"
      v-for="(item, index) in subshopslist" :key="index"
    />
  </div>
</template>

<script>
import ShopCard from "../components/ShopCard";
import { shopslist } from "../api/subnav";
export default {
  components: {
    ShopCard,
  },
  created() {
    shopslist(1).then((res) => {
      this.subshopslist = res.data.data.list;
    });
  },
  data() {
    return {
      shopsnavlist: [
        { one: "精品推荐", two: "品质" },
        { one: "热门榜单", two: "爆款" },
        { one: "新品首发", two: "应季" },
        { one: "促销单品", two: "折扣" },
      ],
      subshopslist: [],
      tabIndex: 0,
    };
  },
  methods: {
    handset(i) {
      this.tabIndex = i;
      shopslist(i + 1).then((res) => {
        this.subshopslist = res.data.data.list;
      });
    },

  },
};
</script>

<style lang="less" scoped>
.shopscard {
  margin-bottom: 50px;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  .shopscard-nav {
    margin: 10px 0;
    padding: 8px 0;
    width: 100%;
    height: 40px;
    display: flex;
    justify-content: space-around;
    text-align: center;
    color: #282828;
    .nav-name.active p {
      color: #fff;
      background: #f95429;
    }
    .nav-name.active h3 {
      color: #f95429;
    }

    p {
      color: #999;
      margin-top: 5px;
      height: 16px;
      font-size: 12px;
      border-radius: 8px;
    }
  }
}
.ShopCard-shop {
  display: flex;
  flex-wrap: wrap;
}
</style>
